package 链表;

/**
 * https://leetcode-cn.com/problems/reverse-linked-list/
 * @author 会玩的洋洋
 *
 */

public class _206_反转链表 {
	public ListNode reverseList(ListNode head) {
		/*
		       递归方法
			if(head == null || head.next == null) return head;
			
			ListNode newListNode = reverseList(head.next);
			head.next.next = head;
			head.next = null;
			return newListNode;
		*/
		/*
		 * 非递归
		 */
		if(head == null || head.next == null) {
            return head;
        }
		ListNode newHead = null;
		while(head != null) {
			ListNode temp = head.next;
			head.next = newHead;
			newHead = head;
			head = temp;
		}
		
		return newHead;
    }
	
}
